//
//  MTActionSheet.m
//  ebook
//
//  Created by 吴超飞 on 16/5/10.
//  Copyright © 2016年 Moton. All rights reserved.
//

#import "MTActionSheet.h"

#define WINDOW_COLOR [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7]

@implementation MTActionSheet

-(id)initWithView:(UIView *)view{
    
    self = [super init];
   
    if (self) {
        //初始化背景视图
        self.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
        self.backgroundColor = WINDOW_COLOR;
        
        self.backGroundView = [[UIView alloc] initWithFrame:view.frame];
        
        rect = CGRectMake((MTScreenW - view.frame.size.width)/2.0f, (MTScreenH - view.frame.size.height) / 2.0f, view.frame.size.width, view.frame.size.height);
    
        view.opaque = NO;
        self.backGroundView.opaque = NO;
        [self.backGroundView setFrame:rect];
        [self.backGroundView addSubview:view];
        [self addSubview:self.backGroundView];
    
    }
    
    return self;
}

-(void)tappedCancel{
    
    [self hide];
}

-(void)show{
  
    [[UIApplication sharedApplication].delegate.window.rootViewController.view addSubview:self];
}

- (void)hide
{
    [UIView animateWithDuration:0.25 animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        if (finished) {
            [self removeFromSuperview];
        }
    }];
}

@end
